package basic.datastruct.List;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/21 15:54
 * @描述 暂无
 */
public class ArrayListBoard {
    public static void main(String[] args) {
        asListTest();
    }
    public static void asListTest(){
        String[] arr=new String[]{"a","b","c"};
        List<String> li=Arrays.asList(arr);
//        li.add("d"); //会报错，因为asList返回的时不可变的List
        System.out.println(li);


        //正确用法时创建新的对应包装类数组，newArrayList（）传入返回的固定长度List
        String[] arr1=new String[]{"a","b","c"};
        List<String> li3=new ArrayList<>(Arrays.asList(arr1));
        li3.add("wdnmd");
        System.out.println(li3);

        int[] intArr=new int[]{1,2,3};
        Integer[] arr4=new Integer[intArr.length];
        for(int i=0;i<intArr.length;i++){
            Integer temp=new Integer(intArr[i]);
            arr4[i]=temp;
        }
        List<Integer> li5=new ArrayList<>(Arrays.asList(arr4));
        li5.add(8);
        System.out.println(li5);

        //或者自己添加
        String[] myArray = { "Apple", "Banana", "Orange" };
        List<String> myList = new ArrayList<String>();
        for (String str : myArray) {
            myList.add(str);
        }
        System.out.println(myList.size());


        //原生类型不会自动装箱
        int[] myArray1 = { 1, 2, 3 };
        List myList1 = Arrays.asList(myArray);
        List li2=myList;
        System.out.println(li2.get(0));
        System.out.println(myList.size());
    }
}
